package com.o2o.cleaning.month.platform.ebusiness_plat.ddmc

import com.alibaba.fastjson.JSON
import org.apache.spark.sql.SparkSession
import org.elasticsearch.spark._

object DingdongMc_es {

  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .appName("SparkTest")
      .master("local[*]")
      .config("es.nodes", "192.168.1.29")
      .config("es.port", "9200")
      .config("es.net.http.auth.user", "elastic")
      .config("es.net.http.auth.pass", "changeme")
      .config("es.batch.write.retry.count", "10")
      .config("es.batch.write.retry.wait", "60")
      .config("cluster.name", "O2OElastic")
      .getOrCreate()
    val sc = spark.sparkContext
    val sqlcontext = spark.sqlContext

    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")

    /** *
      * 需要修改的参数信息
      */
    var year = "2021"
    //    var month = "9"
    var platform = "dingdongmc"

    var monthArr = Array("8")

    for (month <- monthArr) {
      //GET 2021_dingdongmc/dingdongmc_2021_6/_search   迁移3-六月的数据
      var index = s"${year}_${platform}/${platform}_${year}_${month}"
      println(index)
      //      var index247 = s"247_${year}_${platform}/${platform}_${year}_${month}" 这是旧版索引，新版用上面，

      //good路径
      //      var goodPath = s"s3a://dws-data/g_data/2020/${month}/${platform}/"
      var goodPath = s"s3a://o2o-dataproces-group/zyf/${year}/${month}/${platform}/good/"
      //入库
      val df = spark.read.orc(goodPath).where("sellCount>0 and priceText>0").toJSON.rdd.map(line => {

        //flavors类型不一致
        val lines = JSON.parseObject(line)
        lines
      })
        .saveToEs(index, Map("es.mapping.id" -> "good_id"))
    }


  }

}
